<?php
include("config.php");
if (isset($_COOKIE["ImOnline"])){
	//print($_COOKIE["ImOnline"]);
	//print("Welcome back " . $_COOKIE["Username"]);
} else {
	//include("pages/fail.html");
	header( 'Location: index.php?error=You have no access to this page' );
	die("<center><br><br><br><img src=\"img/logo.jpg\" \><br>Your webbrowser dont support redirecting.<br>You have no access to this page. <br><a href=\"index.php\">Please go to main page</a></center>");
	//print($_COOKIE["imonline"]);
	};
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="css/default.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Banrequest - Garrysmod Web</title>
</head>

<body>
<div id="page-wrap">
<?php
include("includes/header.html");
?>
  <?php
	if(isset($_GET['error'])){
	$error = urldecode($_GET['error']);
	print("<p id=\"error\">$error</p>");
	}else{
	print("<p></p>");
	};
  ?>
<p align="left">Ban requests:</p>
<?php
$con = @mysql_connect($host,$username,$password) or die("Cant connect to host");
@mysql_select_db($db) or die( "Unable to select database");

$query="SELECT * FROM banrequests";
$result=mysql_query($query,$con);

$num=mysql_num_rows($result);
?>
<p align="left">
<?php
$i=0;
if ($num == 0){
	print("No banrequests found!");
};
while ($i < $num) {
$Poster=mysql_result($result,$i,"Poster");
$On=mysql_result($result,$i,"On");
$Reason=mysql_result($result,$i,"Reason");
$SteamID=mysql_result($result,$i,"SteamID");
print("$Poster want to ban $On, $SteamID Reason: $Reason<br>");

$i++;
};
mysql_close($con);
?>
<p><br />Bans:</p>
<?php
$con = @mysql_connect($host,$username,$password) or die("Cant connect to host");
@mysql_select_db($db) or die( "Unable to select database");

$query="SELECT * FROM bans";
$result=mysql_query($query,$con);

$num=mysql_num_rows($result);
?>
<p align="left">
<?php
$i=0;
$T=0;
		if($T == 0){
			echo "<table border='0'>
			<tr>
			<th><img src=\"images/icons/trashcan.png\">&nbsp;&nbsp;</th>
			<th>SteamID</th>
			<th>Ingame Nick&nbsp;&nbsp;</th>
			<th>Banner&nbsp;&nbsp;</th>
			<th>Reson&nbsp;&nbsp;</th>
			<th>Time till unban&nbsp;&nbsp;</th>
			</tr>";
			
		};
while ($row = mysql_fetch_array($result)) {
	$Time = intval($row['Bantime']) - time();
	if($row['Bantime'] == 0){
		$Time = 0;
	}else{
		$Time = round($Time / 60);
	};
	if($Time >= 0){
		echo "<tr>";
		echo "<td><a href=\"includes/removeban.php?SteamID=" . $row['SteamID'] . "\"><img src=\"images/icons/trashcan.png\"></a>&nbsp;&nbsp;</td>";
		echo "<td>" . $row['SteamID'] . "&nbsp;&nbsp;</td>";
		echo "<td>" . $row['Nick'] . "&nbsp;&nbsp;</td>";
		echo "<td>" . $row['Banner'] . "&nbsp;&nbsp;</td>";
		echo "<td>" . $row['Comment'] . "&nbsp;&nbsp;</td>";
		if($row['Bantime'] == 0){
			echo "<td>Permabanned</td>";
		}else{
			echo "<td>" . $Time . " Minutes</td>";
		};
	}else{
	$T++;
	};
$i++;
};
echo "</tr>";
echo "</table>";
if($T == $num){
print("No bans found!");
};
mysql_close($con);
?>
</div>
<?php
include("includes/footer.html");
?>
</body>
</html>